package dao

import (
	"github.com/topfreegames/pitaya/fairy/pojo"
	"github.com/topfreegames/pitaya/logger"
	"sync"
)

var (
	GlobalDataDao *globalDataDao
	globalDataDaoOnce sync.Once
)

type globalDataDao struct {
	BaseDao
}

func NewGlobalDataDao() *globalDataDao {
	globalDataDaoOnce.Do(func() {
		GlobalDataDao = &globalDataDao{}
	})
	return GlobalDataDao
}

func (p *globalDataDao) GetGlobalDataByKey(key int) ([]*pojo.GlobalData,error) {
	globalDatas := make([]*pojo.GlobalData,0)
	err :=  p.enginer.Where("nKey=?",key).Find(&globalDatas)
	if err != nil {
		logger.Log.Errorf("GetWorldServer failed,error:%s",err.Error())
		return nil,err
	}
	if len(globalDatas) == 0 {
		return nil,nil
	}

	return globalDatas,nil
}

